// brute force
#include "../constant.h"
#include "./strpos.h"

int Strpos(char str[], char pattern[])
{
    printf("[Brute-Force Core]\n");
    int strLen = StrLen(str);
    int patternLen = StrLen(pattern);
    int i = 0; // scan str
    int j = 0; // scan pattern
    while (i < strLen && j < patternLen)
    {
        if (str[i] == pattern[j])
        {
            i++;
            j++;
        }
        else
        {
            i = i - j + 1; // backtracking
            j = 0;
        }
    }
    if (j >= patternLen)
    {
        return i - patternLen;
    }
    else
    {
        return -1;
    }
}
